package com.haoji.upload.rocketmq;

import com.alibaba.fastjson.JSON;
import com.haoji.upload.dto.UserDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.springframework.stereotype.Service;

/**
 * @program: upload
 * @description:
 * @author: xiaolei
 * @create: 2021-04-21 10:08
 **/
@Slf4j
@Service("addUserHandler")
public class AddUserHandler extends AbstractMqConsumerServiceImpl {

    @Override
    public ConsumeConcurrentlyStatus handle(String message) {
        log.info("mq消息处理开始【添加用户】，message={}", message);
        try {
            UserDTO user = JSON.parseObject(message, UserDTO.class);
            // 模拟做业务操作
            // ....
            System.out.println(user.toString());
        } catch (Exception e) {
            log.error("handler error:{}", e);
            return ConsumeConcurrentlyStatus.RECONSUME_LATER;
        }
        return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
    }
}
